<template>
    <div class="app-container">
        <div>
            <p class="dialogTitle title">当前地震事件:
                <span v-if="currentEvent">{{ currentEvent.eventName }}</span>
                <span v-else>请在地震事件管理中设置当前地震事件</span>
            </p>
        </div>

        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="120px" v-show="showSearch">
            <el-form-item label="拟定烈度" prop="intensityDetermination">
                <el-select v-model="queryParams.intensityDetermination" placeholder="请选择拟定烈度" clearable>
                    <el-option v-for="item in option" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="审核状态" prop="checkStatus">
                <el-select v-model="queryParams.checkStatus" placeholder="请选择审核状态" clearable>
                    <el-option
                        v-for="item in [{ label: '未审核', value: '1' }, { label: '审核通过', value: '2' }, { label: '审核不通过', value: '3' }]"
                        :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="抽样点名称" prop="samplingPointName">
                <el-input v-model="queryParams.samplingPointName" placeholder="请输入抽样点名称" clearable />
            </el-form-item>
            <el-form-item label="样本点房屋编号" prop="samplingPointHouseCode">
                <el-input v-model="queryParams.samplingPointHouseCode" placeholder="请输入样本点房屋编号" clearable />
            </el-form-item>
            <el-form-item label="调查员" prop="createUserName">
                <el-input v-model="queryParams.createUserName" placeholder="请输入调查员" clearable />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="handleQuery">搜索</el-button>
                <el-button @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" :disabled="!currentEvent || dataList.length == 0 || multiple"
                    @click="handleMoreAudie">批量审核</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" :disabled="!currentEvent || dataList.length == 0"
                    @click="handleDel">批量删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" :disabled="!currentEvent || dataList.length == 0"
                    @click="handleExport">导出</el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="dataList" stripe row-key="id" @selection-change="handleSelectionChange">
            <el-table-column type="selection" align="center" :reserve-selection="true" width="55" />
            <el-table-column label="序号" align="center" width="55">
                <template #default="scope">
                    <span>{{ (queryParams.page - 1) * queryParams.rows + scope.$index + 1 }}</span>
                </template>
            </el-table-column>
            <el-table-column label="抽样点房屋编号" align="center" prop="samplingPointHouseCode" show-overflow-tooltip>
                <template #default="scope">
                    <span style="color: #107ce1;cursor: pointer;" @click="handleEdit(scope.row)">{{
                        scope.row.samplingPointHouseCode
                    }}</span>
                </template>
            </el-table-column>
            <el-table-column label="抽样点名称" align="center" prop="samplingPointName" />
            <el-table-column label="拟定烈度" align="center" prop="intensityDetermination">
                <template #default="scope">
                    <span v-if="scope.row.intensityDetermination == '0'">VI度</span>
                    <span v-if="scope.row.intensityDetermination == '1'">VII度</span>
                    <span v-if="scope.row.intensityDetermination == '2'">VIII度</span>
                    <span v-if="scope.row.intensityDetermination == '3'">IX度</span>
                    <span v-if="scope.row.intensityDetermination == '4'">X度</span>
                    <span v-if="scope.row.intensityDetermination == '5'">XI度</span>
                    <span v-if="scope.row.intensityDetermination == '6'">XII度</span>
                </template>
            </el-table-column>
            <el-table-column label="人员伤亡" align="center">
                <template #default="scope">
                    <el-button type="text" @click="handleDelite1(scope.row)">详情查看</el-button>
                </template>
            </el-table-column>
            <el-table-column label="宏观信息" align="center">
                <template #default="scope">
                    <el-button type="text" @click="handleDelite2(scope.row)">详情查看</el-button>
                </template>
            </el-table-column>
            <!-- <el-table-column label="宏观异常现象" align="center" prop="macroscopicAnomaly" show-overflow-tooltip/> -->
            <el-table-column label="宏观异常现象" align="center" prop="macroscopicAnomaly">
                <template #default="scope">
                    <span v-for="(item, index) in scope.row.macroscopicAnomaly.split(',')" :key="index" v-if="scope.row.macroscopicAnomaly">
                        {{transMacroscopicAnomaly(item)}}
                        <span v-if ="index!==scope.row.macroscopicAnomaly.split(',').length-1 ">,</span>
                    </span>
                    <span v-else></span>
                </template>
            </el-table-column>
            <!-- <el-table-column label="地质灾害" align="center" prop="geologicHazard" show-overflow-tooltip /> -->
            <el-table-column label="地质灾害" align="center" prop="geologicHazard">
            <template #default="scope">
                    <span v-for="(item, index) in scope.row.geologicHazard.split(',')" :key="index" v-if="scope.row.geologicHazard">
                        {{transGeologicHazard(item)}}
                        <span v-if ="index!==scope.row.geologicHazard.split(',').length-1 ">,</span>
                    </span>
                    <span v-else></span>
                </template>
            </el-table-column>
            <el-table-column label="调查点震前遥感图" align="center" prop="beforeEarthquakePicture">
                <template #default="scope">
                    <template v-if="scope.row.beforeEarthquakePicture">
                        <el-popover placement="left-start" width="400" trigger="click">
                            <template #reference>
                                <img :src="baseUrl + scope.row.beforeEarthquakePicture[0].attachId"
                                    :alt="baseUrl + scope.row.beforeEarthquakePicture[0].attachId" class="img" />
                            </template>
                            <template #default>
                                <img :src="baseUrl + scope.row.beforeEarthquakePicture[0].attachId" alt=""
                                    class="big" />
                            </template>
                        </el-popover>
                    </template>
                    <template v-else></template>
                </template>
            </el-table-column>
            <el-table-column label="调查后震前遥感图" align="center" prop="afterEarthquakePicture">
                <template #default="scope">
                    <template v-if="scope.row.afterEarthquakePicture">
                        <el-popover placement="left-start" width="400" trigger="click">
                            <template #reference>
                                <img :src="baseUrl + scope.row.afterEarthquakePicture[0].attachId"
                                    :alt="baseUrl + scope.row.afterEarthquakePicture[0].attachId" class="img" />
                            </template>
                            <template #default>
                                <img :src="baseUrl + scope.row.afterEarthquakePicture[0].attachId" alt="" class="big" />
                            </template>
                        </el-popover>
                    </template>
                    <template v-else></template>
                </template>
            </el-table-column>
            <el-table-column label="重复数据编号" align="center" prop="repeatDataCode" show-overflow-tooltip/>
            <el-table-column label="调查员" align="center" prop="createUserName" />
            <el-table-column label="审核状态" align="center" prop="checkStatus">
                <template #default="scope">
                    <span v-if="scope.row.checkStatus == '1'">未审核</span>
                    <span v-if="scope.row.checkStatus == '2'">审核通过</span>
                    <span v-if="scope.row.checkStatus == '3'">审核不通过</span>
                </template>
            </el-table-column>
            <el-table-column label="灾损计算" align="center" prop="isDamnificationCount">
                <template #default="scope">
                    <template v-if="scope.row.isDamnificationCount">
                        <el-checkbox v-model="scope.row.isDamnificationCount" size="large"
                            @change="changeDamnificationCount(scope.row, '0')" />
                    </template>
                    <template v-else>
                        <el-checkbox v-model="scope.row.isDamnificationCount" size="large"
                            @change="changeDamnificationCount(scope.row, '1')" />
                    </template>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
                    <el-button type="text" @click="handleAudit(scope.row)">审核</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows"
            @pagination="getList" />


        <el-dialog title="查看抽样点房屋数据" v-model="open" width="900px" append-to-body>
            <el-form ref="addRef" label-width="150px" :model="form" :rules="rules">
                <el-row style="margin: 20px 0;">
                    <el-col :span="24">
                        <el-form-item label="行政区划" required>
                            <span>{{ form.province }}{{ form.city }}{{ form.area }}{{ form.address }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="抽样点名称" prop="samplingPointName">
                            <el-select v-model="form.samplingPointName" style="width: 100%;">
                                <el-option v-for="item in option4" :key="item.id" :label="item.samplingPointName"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="经度" prop="longitude" required>
                            <el-input v-model="form.longitude" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="纬度" prop="latitude" required>
                            <el-input v-model="form.latitude" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="抽样点户数" prop="samplingPointHouseholds">
                            <el-input v-model="form.samplingPointHouseholds" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="户均房屋面积(平米)" prop="perHouseholdArea">
                            <el-input v-model="form.perHouseholdArea" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="抽样点人口" prop="samplingPointPopulation">
                            <el-input v-model="form.samplingPointPopulation" />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="房屋典型破坏情况">
                            <image-upload ref="uploadRef1" v-model="form.houseTypicalDamage" />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-table style="margin-bottom: 40px;" :data="form.staResult" stripe>
                            <el-table-column label="结构类型" align="center" prop="structureType" />
                            <el-table-column label="毁坏" align="center" prop="destroyArea">
                                <template #default="scope">
                                    <p>{{ scope.row.destroyArea }}</p>
                                    <p style="color: #107ce1;">{{ scope.row.destroyScale }}</p>
                                </template>
                            </el-table-column>
                            <el-table-column label="严重破坏" align="center" prop="seriousDamageArea">
                                <template #default="scope">
                                    <p>{{ scope.row.seriousDamageArea }}</p>
                                    <p style="color: #107ce1;">{{ scope.row.seriousDamageScale }}</p>
                                </template>
                            </el-table-column>
                            <el-table-column label="中等破坏" align="center" prop="moderateDamageArea">
                                <template #default="scope">
                                    <p>{{ scope.row.moderateDamageArea }}</p>
                                    <p style="color: #107ce1;">{{ scope.row.moderateDamageScale }}</p>
                                </template>
                            </el-table-column>
                            <el-table-column label="轻微破坏" align="center" prop="minorDamageArea">
                                <template #default="scope">
                                    <p>{{ scope.row.minorDamageArea }}</p>
                                    <p style="color: #107ce1;">{{ scope.row.minorDamageScale }}</p>
                                </template>
                            </el-table-column>
                            <el-table-column label="基本完好" align="center" prop="basicallyIntactArea">
                                <template #default="scope">
                                    <p>{{ scope.row.basicallyIntactArea }}</p>
                                    <p style="color: #107ce1;">{{ scope.row.basicallyIntactScale }}</p>
                                </template>
                            </el-table-column>
                            <el-table-column label="总面积（平米）" align="center" prop="totalArea" />
                            <el-table-column label="震害指数" align="center" prop="damageIndex">
                                <template #default="scope">
                                    {{decimalTruncation(scope.row.damageIndex)}}
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-col>
                    <!-- 人员伤亡情况 -->
                    <el-col class="tab-title">人员伤亡情况</el-col>
                    <el-col :span="12">
                        <el-form-item label="死亡人数" prop="deathToll">
                            <el-input v-model="form.deathToll" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="失踪人数" prop="disappearToll">
                            <el-input v-model="form.disappearToll" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="重伤人数" prop="seriousInjuryToll">
                            <el-input v-model="form.seriousInjuryToll" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="轻伤人数" prop="minorWoundToll">
                            <el-input v-model="form.minorWoundToll" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="宏观异常现象" prop="macroscopicAnomaly">
                            <el-select v-model="form.macroscopicAnomaly" multiple placeholder="请选择宏观异常现象"
                                style="width: 100%">
                                <el-option v-for="item in option5" :key="item.value" :label="item.label"
                                    :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="地质灾害" prop="geologicHazard">
                            <el-select v-model="form.geologicHazard" multiple placeholder="请选择地质灾害"
                                style="width: 100%">
                                <el-option v-for="item in option6" :key="item.value" :label="item.label"
                                    :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="建筑物震害特征描述">
                            <el-select v-model="form.buildingEarthquakeDescription" multiple placeholder="请选择建筑物震害特征描述"
                                style="width: 100%">
                                <el-option v-for="item in option7" :key="item.value" :label="item.label"
                                    :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="震害特征描述补充">
                            <el-input v-model="form.earthquakeDescription" type="textarea" maxlength="500"
                                show-word-limit :autosize="{ minRows: 5, maxRows: 5 }" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="调查点震前遥感图">
                            <file-upload ref="uploadRef2" v-model="form.beforeEarthquakePicture" :limit="1" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="调查点震后遥感图">
                            <file-upload ref="uploadRef3" v-model="form.afterEarthquakePicture" :limit="1" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="无人机航拍1">
                            <file-upload ref="uploadRef4" v-model="form.uavAerialPhotographyOne" :limit="1" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="无人机航拍2">
                            <file-upload ref="uploadRef5" v-model="form.uavAerialPhotographyTwo" :limit="1" />
                        </el-form-item>
                    </el-col>
                    <!-- 宏观信息 -->
                    <el-col class="tab-title">宏观信息</el-col>
                    <el-col :span="12">
                        <el-form-item label="地形地貌">
                            <el-select v-model="form.topographicFeatures" style="width: 100%;">
                                <el-option v-for="item in option1" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="人员震感情况">
                            <el-select v-model="form.personnelShock" style="width: 100%;">
                                <el-option v-for="item in option2" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="器皿反应情况">
                            <el-select v-model="form.reactionOfVessels" style="width: 100%;">
                                <el-option v-for="item in option3" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="宏观描述">
                            <el-input v-model="form.macroDescription" type="textarea" maxlength="500" show-word-limit
                                :autosize="{ minRows: 5, maxRows: 5 }" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="大范围照片">
                            <file-upload ref="uploadRef6" v-model="form.largeScalePhoto" :limit="1" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="大范围视频">
                            <file-upload ref="uploadRef7" v-model="form.largeScaleVideo" :limit="1" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="烈度拟定" prop="intensityDetermination" required>
                            <el-select v-model="form.intensityDetermination">
                                <el-option v-for="item in option" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="灾情描述">
                            <el-input v-model="form.disasterDescription" type="textarea" maxlength="500" show-word-limit
                                :autosize="{ minRows: 5, maxRows: 5 }" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="照片">
                            <file-upload ref="uploadRef8" v-model="form.enclosurePhoto" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="视频">
                            <file-upload ref="uploadRef9" v-model="form.enclosureVideo" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="音频">
                            <file-upload ref="uploadRef10" v-model="form.enclosureAudio" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="相册">
                            <file-upload ref="uploadRef11" v-model="form.enclosureAlbum" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="handleUpdate">确 认</el-button>
                    <el-button @click="open = false">取 消</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog title="查看人员伤亡" v-model="open1" width="400px" append-to-body>
            <el-form ref="addRef1" label-width="70px" :model="form1">
                <el-row style="margin: 20px 0;">
                    <el-col>
                        <el-form-item label="死亡人数">
                            <el-input v-model="form1.deathToll" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="失踪人数">
                            <el-input v-model="form1.disappearToll" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="重伤人数">
                            <el-input v-model="form1.seriousInjuryToll" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="轻伤人数">
                            <el-input v-model="form1.minorWoundToll" disabled />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="open1 = false">关 闭</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog title="查看宏观信息" v-model="open2" width="800px" append-to-body>
            <el-form ref="addRef2" label-width="120px" :model="form2">
                <el-row style="margin: 20px 0;">
                    <el-col :span="12">
                        <el-form-item label="地形地貌">
                            <el-select v-model="form2.topographicFeatures" style="width: 100%;" disabled>
                                <el-option v-for="item in option1" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="人员情况">
                            <el-input v-model="form2.personnelShock" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="器皿反应情况">
                            <el-select v-model="form2.reactionOfVessels" style="width: 100%;" disabled>
                                <el-option v-for="item in option3" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="宏观描述">
                            <el-input v-model="form2.macroDescription" type="textarea" maxlength="500" show-word-limit
                                :autosize="{ minRows: 5, maxRows: 5 }" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="大范围照片">
                            <image-upload v-model="form2.largeScalePhoto" :limit="1" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="大范围视频">
                            <template v-if="form2.largeScaleVideo">
                                <video controls :src="baseUrl + form2.largeScaleVideo" id="videoId" autoplay
                                    style="width:100%"></video>
                            </template>
                            <template v-else>无</template>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="open2 = false">关 闭</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog title="审核管理" v-model="openAudit" width="600px" append-to-body>
            <el-form ref="auditRef" label-width="80px" :model="form3" :rules="rules">
                <el-row style="margin: 20px 0;">
                    <el-col>
                        <el-form-item label="审核结果" prop="checkStatus">
                            <el-select v-model="form3.checkStatus" style="width: 100%;">
                                <el-option v-for="item in [{ label: '通过', value: '2' }, { label: '不通过', value: '3' }]"
                                    :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="审核意见" prop="checkOpinion">
                            <el-input v-model="form3.checkOpinion" type="textarea" maxlength="500" show-word-limit
                                :autosize="{ minRows: 5, maxRows: 5 }" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="saveAudit">保 存</el-button>
                    <el-button @click="openAudit = false">取 消</el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script setup name="samplePointHouseAudit">
import useEventStore from "@/store/modules/event";
import { getAllList, getDetail, changeStatus, auditSave, getSamPoiList, updateAudit, deleteAudit } from "@/api/fieldWork/surveyAudit/samplePointHouseAudit.js"
const { proxy } = getCurrentInstance();
const dataList = ref([]);
const ids = ref();
const loading = ref(false);
const single = ref(true);
const multiple = ref(true);
const open = ref(false);
const open1 = ref(false);
const open2 = ref(false);
const openAudit = ref(false);
const total = ref(0);
const showSearch = ref(true);
// 烈度拟定
const option = ref([{ label: 'VI度', value: '0' }, { label: 'VII度', value: '1' }, { label: 'VIII度', value: '2' }, { label: 'IX度', value: '3' }, { label: 'X度', value: '4' }, { label: 'XI度', value: '5' }, { label: 'XII度', value: '6' }]);
// 地形地貌
const option1 = ref([{ label: '平原', value: '0' }, { label: '丘陵', value: '1' }, { label: '山地', value: '2' }, { label: '高原', value: '3' }, { label: '盆地', value: '4' }]);
// 人员震感情况
const option2 = ref([{ label: '无震感', value: '0' }, { label: '少数人有震感', value: '1' }, { label: '多数人有震感', value: '2' }, { label: '震感强烈', value: '3' }, { label: '惊慌外逃', value: '4' }, { label: '其他', value: '5' }]);
// 器皿反应情况
const option3 = ref([{ label: '悬挂物摆动', value: '0' }, { label: '不稳器皿作响', value: '1' }, { label: '器皿翻落', value: '2' }, { label: '其他', value: '3' }]);
// 所有抽样点名称
const option4 = ref([]);
const option5 = ref([{ label: '地下水异常', value: '0' }, { label: '生物异常', value: '1' },{ label: '气象异常', value: '2' }, { label: '地声异常', value: '3' },{ label: '地光异常', value: '4' }, { label: '地气异常', value: '5' },{ label: '地动异常', value: '6' }, { label: '地鼓异常', value: '7' },{ label: '电磁异常', value: '8' },{ label: '无异常', value: '9' }]);
const option6 = ref([{ label: '地表破裂', value: '0' }, { label: '地裂锋', value: '1' },{ label: '崩塌', value: '2' }, { label: '滑坡', value: '3' },{ label: '泥石流', value: '4' }, { label: '砂土液化', value: '5' },{ label: '软土震陷', value: '6' }, { label: '其他', value: '7' }]);
const option7 = ref([{ label: '器物翻倒', value: '0' }, { label: '砖烟囱断裂', value: '1' },{ label: '个别房屋局部倒塌', value: '2' }, { label: '少数房屋倒塌', value: '3' },{ label: '多数房屋倒塌', value: '4' }, { label: '房屋普遍倒塌', value: '5' },{ label: '山河改观', value: '6' }]);
const currentEvent = computed(() => useEventStore().currentEvent);
const selectstatus = ref([]);
const isMorestatus = ref(false);
const baseUrl = import.meta.env.VITE_APP_BASE_API + "/attachment/downLoadFile?attachId=";
const validatePositiveNumver = (rule, value, callback) => {
    if (/(^[1-9]\d*$)/.test(value)) {
        callback()
    } else if (!value) {
        callback()
    } else {
        callback(new Error('请输入正整数'))
    }
};
const data = reactive({
    queryParams: {
        page: 1,
        rows: 10,
        intensityDetermination: undefined,
        checkStatus: undefined,
        samplingPointName: undefined,
        samplingPointHouseCode: undefined,
        createUserName: undefined,
    },
    form: {},
    form1: {},
    form2: {},
    form3: {},
    rules: {
        samplingPointName: [{ required: true, trigger: "blur", message: "抽样点名称不能为空" }],
        samplingPointHouseholds: [{ required: false, validator: validatePositiveNumver, trigger: "blur" }],
        perHouseholdArea: [{ required: false, validator: validatePositiveNumver, trigger: "blur" }],
        samplingPointPopulation: [{ required: false, validator: validatePositiveNumver, trigger: "blur" }],
        perHouseholdArea: [{ required: false, validator: validatePositiveNumver, trigger: "blur" }],
        checkStatus: [{ required: true, trigger: "change", message: "审核结果不能为空" }],
        checkOpinion: [{ required: true, trigger: "blur", message: "审核意见不能为空" }],
    }
})
const { queryParams, form, form1, form2, form3, rules } = toRefs(data)


// 修改状态
function changeDamnificationCount(row, state) {
    console.log(row, state);
    changeStatus({ id: row.id, state: state }).then(res => {
        proxy.$modal.msgSuccess("修改完成");
        getList();
    })
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
    single.value = selection.length != 1;
    multiple.value = !selection.length;
    ids.value = selection.map((item) => item.id);
    selectstatus.value = selection;
};
// 批量
function handleMoreAudie() {
    isMorestatus.value = true;
    openAudit.value = true;
    proxy.resetForm("auditRef");
    selectstatus.value = selectstatus.value;
    // form3.value.ids = ids.value.join(',');
}
// 批量删除
function handleDel(){
    let str=''
    let arr=[]
    if(selectstatus.value.length!==0){
        selectstatus.value.forEach((v,i)=>{
            arr.push(v.id)
        })
    }
    str=arr.toString('')
    proxy.$modal
      .confirm("请确认是否要删除选中该抽样点？",)
      .then(function () {
        return deleteAudit(str);
      })
      .then(() => {
        getList();
        proxy.$modal.msgSuccess("删除成功");
      })
      .catch(() => { });
}
// 审核
function handleAudit(row) {
    isMorestatus.value = false;
    openAudit.value = true;
    proxy.resetForm("auditRef");
    // form3.value.ids = row.id;
    selectstatus.value = row;
}

function transMacroscopicAnomaly(val){
	var name = ''
  option5.value.forEach(item => {
		if(item.value == val) {
			name = item.label
			return
		}
	})
	return name
}
function transGeologicHazard(val){
	var name = ''
  option6.value.forEach(item => {
		if(item.value == val) {
			name = item.label
			return
		}
	})
	return name
}

function saveAudit() {
    proxy.$refs["auditRef"].validate(valid => {
        if(isMorestatus.value){
                selectstatus.value.forEach(item=>{
                    item.checkStatus = form3.value.checkStatus;
                    item.checkOpinion = form3.value.checkOpinion;
                    item.xsemId = currentEvent.value.id
                });
            }else{
                selectstatus.value = [{...selectstatus.value,checkStatus:form3.value.checkStatus,checkOpinion:form3.value.checkOpinion,xsemId: currentEvent.value.id}];
            }
        if (valid) {
            auditSave({ list:selectstatus.value }).then(res => {
                proxy.$modal.msgSuccess("审核完成");
                openAudit.value = false;
                getList();
            })
        }
    })
}

function handleDelite1(row) {
    form1.value.deathToll = row.deathToll;
    form1.value.disappearToll = row.disappearToll;
    form1.value.seriousInjuryToll = row.seriousInjuryToll;
    form1.value.minorWoundToll = row.minorWoundToll;
    open1.value = true;
    proxy.resetForm("addRef1");
}

function handleDelite2(row) {
    getDetail({ id: row.id }).then(res => {
        open2.value = true;
        proxy.resetForm("addRef2");
        form2.value.topographicFeatures = res.data.topographicFeatures;
        form2.value.personnelShock = res.data.personnelShock;
        form2.value.reactionOfVessels = res.data.reactionOfVessels;
        form2.value.macroDescription = res.data.macroDescription;
        form2.value.largeScalePhoto = res.data.largeScalePhoto?res.data.largeScalePhoto:[];
        form2.value.largeScaleVideo = res.data.largeScaleVideo?res.data.largeScaleVideo[0].attachId:null;
    })
    
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.page = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    dataList.value = [];
    proxy.resetForm("queryRef");
    handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
    proxy.downloadTemplate('/samPoiHouSur/checkExportExcel', { xsemId: currentEvent.value.id,...queryParams.value }, `抽样点房屋数据.xls`)
}

// 编辑
function handleEdit(row) {
    detail(row.id);
}

//处理附件格式
function eachFiles(fileName) {
    let deepFile = JSON.parse(JSON.stringify(proxy.$refs[fileName].fileList))
    let Ids = []
    for (var i = 0; i < deepFile.length; i++) {
        Ids.push(deepFile[i].attachId)
    }
    return Ids.join(",");
}

function handleUpdate() {
    form.value.houseTypicalDamage = eachFiles('uploadRef1');
    form.value.beforeEarthquakePicture = eachFiles('uploadRef2');
    form.value.afterEarthquakePicture = eachFiles('uploadRef3');
    form.value.uavAerialPhotographyOne = eachFiles('uploadRef4');
    form.value.uavAerialPhotographyTwo = eachFiles('uploadRef5');
    form.value.largeScalePhoto = eachFiles('uploadRef6');
    form.value.largeScaleVideo = eachFiles('uploadRef7');
    form.value.enclosurePhoto = eachFiles('uploadRef8');
    form.value.enclosureVideo = eachFiles('uploadRef9');
    form.value.enclosureAudio = eachFiles('uploadRef10');
    form.value.enclosureAlbum = eachFiles('uploadRef11');
    proxy.$refs["addRef"].validate(valid => {
        if (valid) {
            form.value.buildingEarthquakeDescription = form.value.buildingEarthquakeDescription.join(',');
            form.value.geologicHazard = form.value.geologicHazard.join(',');
            form.value.macroscopicAnomaly = form.value.macroscopicAnomaly.join(',');
            updateAudit({ ...form.value, xsemId: currentEvent.value.id }).then(res => {
                proxy.$modal.msgSuccess("修改成功");
                open.value = false;
                getList();
            })
        }
    });
}

// 查看
function detail(id) {
    getDetail({ id: id }).then(res => {
        open.value = true;
        proxy.resetForm("addRef");
        form.value = res.data;
        form.value.buildingEarthquakeDescription = form.value.buildingEarthquakeDescription.split(',');
        form.value.geologicHazard = form.value.geologicHazard.split(',');
        form.value.macroscopicAnomaly = form.value.macroscopicAnomaly.split(',');
    })
}

/** 查询数据列表 */
function getList() {
    if (currentEvent.value) {
        loading.value = true;
        getAllList({ ...queryParams.value, xsemId: currentEvent.value.id }).then(response => {
            if (response.data.rows) {
                response.data.rows.forEach(item => {
                    if (item.isDamnificationCount == '1') {
                        item.isDamnificationCount = true;
                    } else if (item.isDamnificationCount == '0') {
                        item.isDamnificationCount = false;
                    }
                })
            }
            dataList.value = response.data.rows ? response.data.rows : [];
            total.value = response.data.total;
            loading.value = false;
        });
    } else {
        dataList.value = [];
        total.value = 0;
    }
}

/** 查询所有抽样点名称 */
function getAllSamPoiList() {
    if (currentEvent.value) {
        getSamPoiList({ xsemId: currentEvent.value.id }).then(response => {
            option4.value = response.data;
        });
    } else {
        option4.value = [];
    }
}
function decimalTruncation(val) {
    let num = ''
    if(val != undefined) {
        let a = parseFloat(val)
        num = Math.ceil(a * 100) / 100
    }
    return num
}
onMounted(() => {
    setTimeout(() => {
        getList();
        getAllSamPoiList();
    }, 200)
})
</script>

<style scoped lang="scss">
.title {
    margin: 0 0 20px !important;
}

.tab-title {
    font-size: 16px;
    font-weight: bold;
    border-left: 4px solid #0D9AFF;
    font-family: PingFangSC-Medium;
    padding-left: 10px;
    margin-bottom: 20px;
}

.img {
    width: 80px;
    height: 80px;
    padding: 10px;
}

.big {
    width: 400px;
    padding: 20px;
}
</style>

